package com.zhongkeruan.product.controller;

import com.zhongkeruan.common.constants.StatusCode;
import com.zhongkeruan.common.model.Product;
import com.zhongkeruan.common.vo.Result;
import com.zhongkeruan.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yangyao
 * @Description: UserController
 * @date 2019/1/11 15:12
 */
@RestController
@RequestMapping(value = "/products")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping
    public Result getUserList() throws Exception{
        List<Product> productList = productService.getProductList();
        return new Result(StatusCode.SUCCESS,"查询成功", productList);
    }

    @RequestMapping("/{id}")
    public Result getUserById(@PathVariable("id") Long id) throws Exception{
        Product product = productService.getProductById(id);
        return new Result(StatusCode.SUCCESS,"查询成功", product);
    }

    @PostMapping
    public Result addProduct(@RequestBody Product product) throws Exception{
        productService.addProduct(product);
        return new Result(StatusCode.SUCCESS,"添加成功");
    }
}
